﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using Teigha.Core;

namespace Teigha.TD
{
	public class OdDbXrecord : OdDbObject
	{
		[EditorBrowsable(EditorBrowsableState.Never)]
		public OdDbXrecord(IntPtr cPtr, bool cMemoryOwn) : base(TD_DbPINVOKE.OdDbXrecord_SWIGUpcast(cPtr), cMemoryOwn)
		{
			this.swigCPtr = new HandleRef(this, cPtr);
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public static HandleRef getCPtr(OdDbXrecord obj)
		{
			if (obj != null)
			{
				return obj.swigCPtr;
			}
			return new HandleRef(null, IntPtr.Zero);
		}

		~OdDbXrecord()
		{
			this.Dispose();
		}

		public override void Dispose()
		{
			if (this.swigCPtr.Handle != IntPtr.Zero)
			{
				if (this.swigCMemOwn)
				{
					lock (this.locker)
					{
						if (this.swigCPtr.Handle != IntPtr.Zero && this.swigCMemOwn)
						{
							this.swigCMemOwn = false;
							TD_DbPINVOKE.delete_OdDbXrecord(this.swigCPtr);
						}
					}
					this.swigCMemOwn = false;
				}
				this.swigCPtr = new HandleRef(null, IntPtr.Zero);
			}
			GC.SuppressFinalize(this);
			base.Dispose();
		}

		public new static OdDbXrecord cast(OdRxObject pObj)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbXrecord_cast(OdRxObject.getCPtr(pObj));
			OdDbXrecord result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbXrecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbXrecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbXrecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new static OdRxClass desc()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbXrecord_desc(), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxClass isA()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbXrecord_isA(this.swigCPtr), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxObject queryX(OdRxClass protocolClass)
		{
			OdRxObject result = Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbXrecord_queryX(this.swigCPtr, OdRxClass.getCPtr(protocolClass)), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new static OdDbXrecord createObject()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbXrecord_createObject();
			OdDbXrecord result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbXrecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbXrecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbXrecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResBuf rbChain(OdDbDatabase pDb, out OdResult pStatus)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbXrecord_rbChain__SWIG_0(this.swigCPtr, OdDbDatabase.getCPtr(pDb), out pStatus);
			OdResBuf result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdResBuf)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdResBuf)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdResBuf)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResBuf rbChain(OdDbDatabase pDb)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbXrecord_rbChain__SWIG_1(this.swigCPtr, OdDbDatabase.getCPtr(pDb));
			OdResBuf result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdResBuf)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdResBuf)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdResBuf)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResBuf rbChain()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbXrecord_rbChain__SWIG_2(this.swigCPtr);
			OdResBuf result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdResBuf)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdResBuf)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdResBuf)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdDbXrecordIterator newIterator(OdDbDatabase pDb)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbXrecord_newIterator__SWIG_0(this.swigCPtr, OdDbDatabase.getCPtr(pDb));
			OdDbXrecordIterator result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbXrecordIterator)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbXrecordIterator)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbXrecordIterator)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdDbXrecordIterator newIterator()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbXrecord_newIterator__SWIG_1(this.swigCPtr);
			OdDbXrecordIterator result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbXrecordIterator)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbXrecordIterator)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbXrecordIterator)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public void setFromRbChain(OdResBuf pRb, OdDbDatabase pDb)
		{
			TD_DbPINVOKE.OdDbXrecord_setFromRbChain__SWIG_0(this.swigCPtr, OdResBuf.getCPtr(pRb), OdDbDatabase.getCPtr(pDb));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public void setFromRbChain(OdResBuf pRb)
		{
			TD_DbPINVOKE.OdDbXrecord_setFromRbChain__SWIG_1(this.swigCPtr, OdResBuf.getCPtr(pRb));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public void appendRbChain(OdResBuf pRb, OdDbDatabase pDb)
		{
			TD_DbPINVOKE.OdDbXrecord_appendRbChain__SWIG_0(this.swigCPtr, OdResBuf.getCPtr(pRb), OdDbDatabase.getCPtr(pDb));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public void appendRbChain(OdResBuf pRb)
		{
			TD_DbPINVOKE.OdDbXrecord_appendRbChain__SWIG_1(this.swigCPtr, OdResBuf.getCPtr(pRb));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public bool isXlateReferences()
		{
			bool result = TD_DbPINVOKE.OdDbXrecord_isXlateReferences(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public void setXlateReferences(bool isXlateReferences)
		{
			TD_DbPINVOKE.OdDbXrecord_setXlateReferences(this.swigCPtr, isXlateReferences);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public new virtual OdResult dwgInFields(OdDbDwgFiler pFiler)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbXrecord_dwgInFields(this.swigCPtr, OdDbDwgFiler.getCPtr(pFiler));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual void dwgOutFields(OdDbDwgFiler pFiler)
		{
			TD_DbPINVOKE.OdDbXrecord_dwgOutFields(this.swigCPtr, OdDbDwgFiler.getCPtr(pFiler));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public new virtual OdResult dxfInFields(OdDbDxfFiler pFiler)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbXrecord_dxfInFields(this.swigCPtr, OdDbDxfFiler.getCPtr(pFiler));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual void dxfOutFields(OdDbDxfFiler pFiler)
		{
			TD_DbPINVOKE.OdDbXrecord_dxfOutFields(this.swigCPtr, OdDbDxfFiler.getCPtr(pFiler));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public new virtual DuplicateRecordCloning mergeStyle()
		{
			DuplicateRecordCloning result = (DuplicateRecordCloning)TD_DbPINVOKE.OdDbXrecord_mergeStyle(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual void setMergeStyle(DuplicateRecordCloning mergeStyle)
		{
			TD_DbPINVOKE.OdDbXrecord_setMergeStyle(this.swigCPtr, (int)mergeStyle);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual OdResult subGetClassID(IntPtr pClsid)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbXrecord_subGetClassID(this.swigCPtr, pClsid);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdDbXrecord open(OdDbObject pObject, string key, int creationFlag, DuplicateRecordCloning mergeStyle)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbXrecord_open__SWIG_0(OdDbObject.getCPtr(pObject), key, creationFlag, (int)mergeStyle);
			OdDbXrecord result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbXrecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbXrecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbXrecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdDbXrecord open(OdDbObject pObject, string key, int creationFlag)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbXrecord_open__SWIG_1(OdDbObject.getCPtr(pObject), key, creationFlag);
			OdDbXrecord result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbXrecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbXrecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbXrecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdDbXrecord open(OdDbObject pObject, string key)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbXrecord_open__SWIG_2(OdDbObject.getCPtr(pObject), key);
			OdDbXrecord result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbXrecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbXrecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbXrecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdDbXrecord open(OdDbObject pObject, OdStringArray keys, int creationFlag, DuplicateRecordCloning mergeStyle)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbXrecord_open__SWIG_3(OdDbObject.getCPtr(pObject), OdStringArray.getCPtr(keys), creationFlag, (int)mergeStyle);
			OdDbXrecord result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbXrecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbXrecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbXrecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdDbXrecord open(OdDbObject pObject, OdStringArray keys, int creationFlag)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbXrecord_open__SWIG_4(OdDbObject.getCPtr(pObject), OdStringArray.getCPtr(keys), creationFlag);
			OdDbXrecord result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbXrecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbXrecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbXrecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdDbXrecord open(OdDbObject pObject, OdStringArray keys)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbXrecord_open__SWIG_5(OdDbObject.getCPtr(pObject), OdStringArray.getCPtr(keys));
			OdDbXrecord result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbXrecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbXrecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbXrecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public const int kOpenExisting = 0;

		public const int kCreateIfNotFound = 1;

		private object locker = new object();

		private HandleRef swigCPtr;
	}
}
